package com.bussiness.controller;


import com.bussiness.auto.JSONAuthentication;
import com.bussiness.entity.UserMeans;
import com.bussiness.mapper.UserMeansMapper;
import com.bussiness.response.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author bussiness
 * @since 2022-03-29
 */
@RestController
@RequestMapping("/user-means")
public class UserMeansController extends JSONAuthentication {
    @Autowired
    UserMeansMapper userMeansMapper;
    @ApiOperation(value = "添加用户,身份已给默认值")
    @PostMapping("/add")
    public void addUser(HttpServletRequest request, HttpServletResponse response, @RequestBody UserMeans userMeans) throws  Exception{
        if(userMeansMapper.insert(userMeans)>0){
            Result ok = Result.ok().message("添加成功");
            this.WriteJSON(request, response, ok);
        }else{
            Result error = Result.error();
            this.WriteJSON(request, response, error);
        }
    }
    @ApiOperation(value = "删除资料")
    @PostMapping("/del")
    public void delUser(HttpServletRequest request, HttpServletResponse response, @RequestParam("userId") int userId ) throws Exception{
        int i=userMeansMapper.deleteById(userId);
        if(i>0){
            Result ok = Result.ok();
            this.WriteJSON(request, response, ok);
        } else {
            Result error = Result.error();
            this.WriteJSON(request, response, error);
        }
    }
    @ApiOperation(value = "修改用户资料")
    @PostMapping("/upd")
    public void updMeans(HttpServletRequest request, HttpServletResponse response,  @RequestBody UserMeans userMeans ) throws Exception{
        if(userMeansMapper.updateById(userMeans)>0){
            Result ok = Result.ok().message("修改成功");
            this.WriteJSON(request, response, ok);
        } else {
            Result error = Result.error();
            this.WriteJSON(request, response, error);
        }
    }

}

